home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD1320412312000.psc / Transparent Menu.frm (.txt) next >
Encoding:
Visual Basic Form  |  2000-12-31  |  13.2 KB  |  442 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Alpha Blend Menu Example - 
  4.  2000 Aaron Wilkes"
  5.    ClientHeight    =   3735
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   5625
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   3735
  11.    ScaleWidth      =   5625
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.HScrollBar HScroll1 
  14.       Height          =   255
  15.       Left            =   3360
  16.       Max             =   255
  17.       TabIndex        =   11
  18.       Top             =   1200
  19.       Width           =   2175
  20.    End
  21.    Begin VB.CommandButton Command3 
  22.       Caption         =   "Reset Form"
  23.       Height          =   495
  24.       Left            =   3600
  25.       TabIndex        =   10
  26.       Top             =   3240
  27.       Width           =   1935
  28.    End
  29.    Begin VB.CommandButton Command2 
  30.       Caption         =   "Show Picture"
  31.       Height          =   615
  32.       Left            =   3600
  33.       TabIndex        =   9
  34.       Top             =   2640
  35.       Width           =   1935
  36.    End
  37.    Begin VB.Timer Timer2 
  38.       Enabled         =   0   'False
  39.       Interval        =   1
  40.       Left            =   4080
  41.       Top             =   1560
  42.    End
  43.    Begin VB.CommandButton Command1 
  44.       Caption         =   "Change Background Color"
  45.       Height          =   615
  46.       Left            =   3600
  47.       TabIndex        =   3
  48.       Top             =   2040
  49.       Width           =   1935
  50.    End
  51.    Begin VB.Timer Timer1 
  52.       Enabled         =   0   'False
  53.       Interval        =   1
  54.       Left            =   3600
  55.       Top             =   1560
  56.    End
  57.    Begin VB.PictureBox Picture2 
  58.       BorderStyle     =   0  'None
  59.       Height          =   2250
  60.       Left            =   0
  61.       Picture         =   "Transparent Menu.frx":0000
  62.       ScaleHeight     =   150
  63.       ScaleMode       =   3  'Pixel
  64.       ScaleWidth      =   61
  65.       TabIndex        =   1
  66.       Top             =   730
  67.       Visible         =   0   'False
  68.       Width           =   915
  69.       Begin VB.Label MnuLab 
  70.          BackStyle       =   0  'Transparent
  71.          Caption         =   "Exit"
  72.          Height          =   255
  73.          Index           =   4
  74.          Left            =   240
  75.          TabIndex        =   8
  76.          Top             =   1560
  77.          Width           =   495
  78.       End
  79.       Begin VB.Label MnuLab 
  80.          BackStyle       =   0  'Transparent
  81.          Caption         =   "Print"
  82.          Height          =   255
  83.          Index           =   3
  84.          Left            =   240
  85.          TabIndex        =   7
  86.          Top             =   1200
  87.          Width           =   375
  88.       End
  89.       Begin VB.Label MnuLab 
  90.          BackStyle       =   0  'Transparent
  91.          Caption         =   "Save"
  92.          Height          =   255
  93.          Index           =   2
  94.          Left            =   240
  95.          TabIndex        =   6
  96.          Top             =   840
  97.          Width           =   495
  98.       End
  99.       Begin VB.Label MnuLab 
  100.          BackStyle       =   0  'Transparent
  101.          Caption         =   "Open"
  102.          Height          =   255
  103.          Index           =   1
  104.          Left            =   240
  105.          TabIndex        =   5
  106.          Tag             =   "32"
  107.          Top             =   480
  108.          Width           =   495
  109.       End
  110.       Begin VB.Label MnuLab 
  111.          BackStyle       =   0  'Transparent
  112.          Caption         =   "New"
  113.          Height          =   255
  114.          Index           =   0
  115.          Left            =   240
  116.          TabIndex        =   4
  117.          Tag             =   "8"
  118.          Top             =   120
  119.          Width           =   495
  120.       End
  121.    End
  122.    Begin VB.PictureBox Picture1 
  123.       BorderStyle     =   0  'None
  124.       Height          =   750
  125.       Left            =   0
  126.       Picture         =   "Transparent Menu.frx":6C12
  127.       ScaleHeight     =   50
  128.       ScaleMode       =   3  'Pixel
  129.       ScaleWidth      =   375
  130.       TabIndex        =   0
  131.       Top             =   0
  132.       Width           =   5625
  133.       Begin VB.Label Label1 
  134.          AutoSize        =   -1  'True
  135.          BackStyle       =   0  'Transparent
  136.          Caption         =   "&File"
  137.          BeginProperty Font 
  138.             Name            =   "MS Sans Serif"
  139.             Size            =   13.5
  140.             Charset         =   0
  141.             Weight          =   400
  142.             Underline       =   0   'False
  143.             Italic          =   0   'False
  144.             Strikethrough   =   0   'False
  145.          EndProperty
  146.          ForeColor       =   &H00000000&
  147.          Height          =   360
  148.          Left            =   240
  149.          TabIndex        =   2
  150.          Top             =   120
  151.          Width           =   465
  152.       End
  153.    End
  154.    Begin VB.Label Label2 
  155.       BackColor       =   &H000000FF&
  156.       Caption         =   "Opacity Value: "
  157.       Height          =   315
  158.       Left            =   3480
  159.       TabIndex        =   12
  160.       Top             =   840
  161.       Width           =   2010
  162.    End
  163.    Begin VB.Image Image2 
  164.       Height          =   375
  165.       Left            =   5160
  166.       Top             =   1560
  167.       Visible         =   0   'False
  168.       Width           =   375
  169.    End
  170.    Begin VB.Image Image1 
  171.       Height          =   375
  172.       Left            =   4560
  173.       Picture         =   "Transparent Menu.frx":148A4
  174.       Stretch         =   -1  'True
  175.       Top             =   1560
  176.       Visible         =   0   'False
  177.       Width           =   495
  178.    End
  179. Attribute VB_Name = "Form1"
  180. Attribute VB_GlobalNameSpace = False
  181. Attribute VB_Creatable = False
  182. Attribute VB_PredeclaredId = True
  183. Attribute VB_Exposed = False
  184. Option Explicit
  185. Private Type BLENDFUNCTION
  186.   BlendOp As Byte
  187.   BlendFlags As Byte
  188.   SourceConstantAlpha As Byte
  189.   AlphaFormat As Byte
  190. End Type
  191. Const AC_SRC_OVER = &H0
  192. Dim I As Long, A As Long
  193. Dim Opacity As Integer
  194. Dim BF As BLENDFUNCTION, lBF As Long
  195. Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal BLENDFUNCT As Long) As Long
  196. Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long)
  197. Dim MnuFileOpened As Boolean
  198. Private Sub Command1_Click()
  199. If MnuFileOpened Then
  200. Timer2.Enabled = True
  201. MnuFileOpened = False
  202. End If
  203. Form1.BackColor = vbRed
  204. Picture1.Cls
  205. With BF
  206. .BlendOp = AC_SRC_OVER
  207. .BlendFlags = 0
  208. .SourceConstantAlpha = Opacity
  209. .AlphaFormat = 0
  210. End With
  211. RtlMoveMemory lBF, BF, 4
  212. AlphaBlend Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Form1.hdc, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, lBF
  213. Picture1.Refresh
  214. End Sub
  215. Private Sub Command2_Click()
  216. If MnuFileOpened Then
  217. Timer2.Enabled = True
  218. MnuFileOpened = False
  219. End If
  220. Form1.Picture = Image1.Picture
  221. Picture1.Cls
  222. With BF
  223. .BlendOp = AC_SRC_OVER
  224. .BlendFlags = 0
  225. .SourceConstantAlpha = Opacity
  226. .AlphaFormat = 0
  227. End With
  228. RtlMoveMemory lBF, BF, 4
  229. AlphaBlend Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Form1.hdc, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, lBF
  230. Picture1.Refresh
  231. End Sub
  232. Private Sub Command3_Click()
  233. If MnuFileOpened Then
  234. Timer2.Enabled = True
  235. MnuFileOpened = False
  236. End If
  237. Form1.BackColor = &H8000000F
  238. Form1.Picture = Image2.Picture
  239. Picture1.Cls
  240. With BF
  241. .BlendOp = AC_SRC_OVER
  242. .BlendFlags = 0
  243. .SourceConstantAlpha = Opacity
  244. .AlphaFormat = 0
  245. End With
  246. RtlMoveMemory lBF, BF, 4
  247. AlphaBlend Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Form1.hdc, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, lBF
  248. Picture1.Refresh
  249. End Sub
  250. Private Sub Form_Click()
  251. If MnuFileOpened Then
  252. Timer2.Enabled = True
  253. MnuFileOpened = False
  254. End If
  255. End Sub
  256. Private Sub Form_Load()
  257. HScroll1.Value = 128
  258. For I = 0 To MnuLab.Count - 1
  259. MnuLab(I).Tag = MnuLab(I).Top
  260. MnuLab(I).Visible = False
  261. Next I
  262. Picture1.Visible = True
  263. Form1.AutoRedraw = True
  264. Picture1.AutoRedraw = True
  265. Form1.ScaleMode = vbPixels
  266. Picture1.ScaleMode = vbPixels
  267. With BF
  268. .BlendOp = AC_SRC_OVER
  269. .BlendFlags = 0
  270. .SourceConstantAlpha = Opacity
  271. .AlphaFormat = 0
  272. End With
  273. RtlMoveMemory lBF, BF, 4
  274. AlphaBlend Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Form1.hdc, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, lBF
  275. End Sub
  276. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  277. Label1.ForeColor = RGB(0, 0, 0)
  278. For A = 0 To MnuLab.Count - 1
  279. MnuLab(A).ForeColor = RGB(0, 0, 0)
  280. Next A
  281. End Sub
  282. Private Sub Form_Unload(Cancel As Integer)
  283. End Sub
  284. Private Sub HScroll1_Change()
  285. Label2.Caption = "Opacity Value" & Str$(HScroll1.Value)
  286. Opacity = HScroll1.Value
  287. Picture1.Cls
  288. With BF
  289. .BlendOp = AC_SRC_OVER
  290. .BlendFlags = 0
  291. .SourceConstantAlpha = Opacity
  292. .AlphaFormat = 0
  293. End With
  294. RtlMoveMemory lBF, BF, 4
  295. AlphaBlend Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Form1.hdc, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, lBF
  296. Picture1.Refresh
  297. End Sub
  298. Private Sub HScroll1_Scroll()
  299. Label2.Caption = "Opacity Value" & Str$(HScroll1.Value)
  300. Opacity = HScroll1.Value
  301. Picture1.Cls
  302. With BF
  303. .BlendOp = AC_SRC_OVER
  304. .BlendFlags = 0
  305. .SourceConstantAlpha = Opacity
  306. .AlphaFormat = 0
  307. End With
  308. RtlMoveMemory lBF, BF, 4
  309. AlphaBlend Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Form1.hdc, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, lBF
  310. Picture1.Refresh
  311. End Sub
  312. Private Sub Label1_Click()
  313. If Not MnuFileOpened Then
  314. Picture2.Visible = True
  315. Form1.AutoRedraw = True
  316. Picture2.AutoRedraw = True
  317. Form1.ScaleMode = vbPixels
  318. Picture2.ScaleMode = vbPixels
  319. With BF
  320. .BlendOp = AC_SRC_OVER
  321. .BlendFlags = 0
  322. .SourceConstantAlpha = 255
  323. .AlphaFormat = 0
  324. End With
  325. RtlMoveMemory lBF, BF, 4
  326. AlphaBlend Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Form1.hdc, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, lBF
  327. Timer1.Enabled = True
  328. MnuFileOpened = True
  329. End If
  330. End Sub
  331. Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  332. Label1.ForeColor = RGB(0, 255, 0)
  333. If Label1.Top < 9 Then
  334. Label1.Top = Label1.Top + 8
  335. End If
  336. End Sub
  337. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  338. Label1.ForeColor = RGB(0, 255, 0)
  339. For A = 0 To MnuLab.Count - 1
  340. MnuLab(A).ForeColor = RGB(0, 0, 0)
  341. Next A
  342. End Sub
  343. Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  344. Label1.ForeColor = RGB(0, 255, 0)
  345. If Label1.Top > 14 Then
  346. Label1.Top = Label1.Top - 8
  347. End If
  348. End Sub
  349. Private Sub MnuLab_Click(Index As Integer)
  350. Dim Ret As Long
  351. Select Case Index
  352. Case 0
  353. MsgBox "New", vbOKOnly + vbInformation, "You Chose..."
  354. Case 1
  355. MsgBox "Open", vbOKOnly + vbInformation, "You Chose..."
  356. Case 2
  357. MsgBox "Save", vbOKOnly + vbInformation, "You Chose..."
  358. Case 3
  359. MsgBox "Print", vbOKOnly + vbInformation, "You Chose..."
  360. Case 4
  361. MsgBox "Quit", vbOKOnly + vbInformation, "You Chose..."
  362. Ret = MsgBox("Do you want to quit?", vbYesNo + vbInformation, "Quit?!?")
  363. If Ret = vbYes Then
  364. Unload Me
  365. End If
  366. End Select
  367. End Sub
  368. Private Sub MnuLab_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  369. If MnuLab(Index).Top < MnuLab(Index).Tag + 1 Then
  370. MnuLab(Index).Top = MnuLab(Index).Top + 4
  371. End If
  372. End Sub
  373. Private Sub MnuLab_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  374. For A = 0 To MnuLab.Count - 1
  375. MnuLab(A).ForeColor = RGB(0, 0, 0)
  376. Next A
  377. MnuLab(Index).ForeColor = RGB(0, 255, 0)
  378. End Sub
  379. Private Sub MnuLab_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  380. If MnuLab(Index).Top > MnuLab(Index).Tag + 1 Then
  381. MnuLab(Index).Top = MnuLab(Index).Top - 4
  382. End If
  383. End Sub
  384. Private Sub Picture1_Click()
  385. If MnuFileOpened Then
  386. Timer2.Enabled = True
  387. MnuFileOpened = False
  388. End If
  389. End Sub
  390. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  391. Label1.ForeColor = RGB(0, 0, 0)
  392. For A = 0 To MnuLab.Count - 1
  393. MnuLab(A).ForeColor = RGB(0, 0, 0)
  394. Next A
  395. End Sub
  396. Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  397. For A = 0 To MnuLab.Count - 1
  398. MnuLab(A).ForeColor = RGB(0, 0, 0)
  399. Next A
  400. End Sub
  401. Private Sub Timer1_Timer()
  402. For I = 255 To Opacity Step -30
  403. If I > Opacity - 1 Then
  404. For A = 0 To MnuLab.Count - 1
  405. MnuLab(A).Visible = True
  406. Next A
  407. End If
  408. Timer1.Enabled = False
  409. Picture2.Cls
  410. With BF
  411. .BlendOp = AC_SRC_OVER
  412. .BlendFlags = 0
  413. .SourceConstantAlpha = I
  414. .AlphaFormat = 0
  415. End With
  416. RtlMoveMemory lBF, BF, 4
  417. AlphaBlend Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Form1.hdc, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, lBF
  418. Picture2.Refresh
  419. Next I
  420. End Sub
  421. Private Sub Timer2_Timer()
  422. For I = Opacity To 255 Step 30
  423. If I > 254 - 30 Then
  424. Picture2.Visible = False
  425. Timer2.Enabled = False
  426. For A = 0 To MnuLab.Count - 1
  427. MnuLab(A).Visible = False
  428. Next A
  429. End If
  430. Picture2.Cls
  431. With BF
  432. .BlendOp = AC_SRC_OVER
  433. .BlendFlags = 0
  434. .SourceConstantAlpha = I
  435. .AlphaFormat = 0
  436. End With
  437. RtlMoveMemory lBF, BF, 4
  438. AlphaBlend Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Form1.hdc, 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, lBF
  439. Picture2.Refresh
  440. Next I
  441. End Sub
  442.